import VueRouter from 'vue-router'
import Vue from 'vue'
Vue.use(VueRouter)

const routes = [
  { path: '/',name: '', redirect: '/portal' },
  { path: '/portal',name: 'UserLogin', component: () => import('../views/auth/UserLogin.vue')},
  { path: '/userRegistry',name: 'UserRegistry', component: () => import('../views/auth/UserRegistry.vue') },
  { path: '/index', name: 'SystemIndex',component: () => import('../views/SystemIndex.vue') ,
      redirect: '/redirectIndex',
      children:[
        { path: '/redirectIndex', name: 'SystemRedirectIndex', component: () => import('../views/others/SystemRedirectIndex.vue') },
        { path: '/bookList',name: 'BookList', component: () => import('../views/books/BookList.vue') },
        { path: '/uploadBook',name: 'UploadBook', component: () => import('../views/books/UploadBook.vue') },
        { path: '/bookTypes',name: 'BookType', component: () => import('../views/books/BookType.vue') },
        { path: '/userList', name: 'UserList', component: () => import('../views/auth/UserList.vue')},
      ]
  }
]

const router = new VueRouter({
    // 使用history模式，打包后Windows中执行index.html访问不到404
    mode: 'hash',
    routes
})

//路由守卫
// router.beforeEach((to, from, next) => {
//     if(to.name === 'FreePlanetIndex' || to.name === 'PlanetLoginRegister'){
//         next()
//     }else{
//         if(isLogin()){
//             next()
//         }else{
//             next({name: 'PlanetLoginRegister'})
//         }
//     }
// })

export default router